//
//  CVCellOfMyPublish.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/23.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "CVCellOfMyPublish.h"
#import "BaseTableView.h"
#import "MJMacro.h"
#import "ZWYNetTool.h"
// 文章
#import "TVCellOfArticleInMyPublish.h"
// 提问
#import "TVCellOfAskInMyPublish.h"
//  回答
#import "TVCellOfMyPublish.h"
//  回答的models
#import "AnswerOfDataMyPublish.h"
#import "DataOfMyPublish.h"
#import "QuestionOfAnswerDataMyPublish.h"
#import "RootClassOfMyPublish.h"
#import "UserOfAnswerDataMyPublish.h"
// 提问的models
#import "DataOfAskInMyPublish.h"
#import "QuestionOfDataAskInMyPublish.h"
#import "RootClassOfAskInMyPublish.h"
#import "UserOfQuestionDataAskInMyPublish.h"
@interface CVCellOfMyPublish()<UITableViewDelegate, UITableViewDataSource>
// tableView
@property (nonatomic, strong) BaseTableView *tableViewOfMyPublish;
// 回答的 model
@property (nonatomic, strong) RootClassOfMyPublish *rootClassOfMyPublish;
// 提问的 model
@property (nonatomic, strong) RootClassOfAskInMyPublish *rootClassOfAskInMyPublish;
@end
@implementation CVCellOfMyPublish
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableView];
        //发布的提问, 数据解析
        [self handleAskInMyPublicData];
        // 发布的回答,数据解析
        [self handleAnswerInMyPublicData];
    }
    return self;
}
#pragma mark - 发布的回答,数据解析
- (void)handleAnswerInMyPublicData{
    [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/my-newans-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&token=0d4eeb8732f9ae2c73401002570ceb93" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
//        NSLog(@"%@", result);
        _rootClassOfMyPublish = [RootClassOfMyPublish modelDic:result];
        [self.tableViewOfMyPublish reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
#pragma mark - 发布的提问, 数据解析
- (void)handleAskInMyPublicData{
    [ZWYNetTool GET:@"http://yiapi.xinli001.com/v2/yi/my-newque-list.json?key=18ee0593a01c07f71d28fa936d671457&_platform=ios&_version=4.0&token=0d4eeb8732f9ae2c73401002570ceb93" andBody:nil andHeader:nil andResponse:ZWYJSON andSuccessBlock:^(id result) {
//        NSLog(@"%@", result);
        _rootClassOfAskInMyPublish = [RootClassOfAskInMyPublish modelDic:result];
        [self.tableViewOfMyPublish reloadData];
    } andFailureBlock:^(NSError *error) {
        
    }];
}
#pragma mark - 创建 tableView
- (void)createTableView{
    self.tableViewOfMyPublish = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    [self.contentView addSubview:_tableViewOfMyPublish];
    self.tableViewOfMyPublish.delegate = self;
    self.tableViewOfMyPublish.dataSource = self;
    // 文章
    [self.tableViewOfMyPublish registerNib:[UINib nibWithNibName:@"TVCellOfArticleInMyPublish" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfArticleInMyPublish"];
    // 提问
    [self.tableViewOfMyPublish registerNib:[UINib nibWithNibName:@"TVCellOfAskInMyPublish" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfAskInMyPublish"];
    // 回答
    [self.tableViewOfMyPublish registerNib:[UINib nibWithNibName:@"TVCellOfMyPublish" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TVCellOfMyPublish"];
}
#pragma mark - tabelView 代理方法 row 的数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return _rootClassOfArticleCollect.data.favorite.count;
    NSLog(@"---------0:%ld", _numberOfRow);
    switch (_numberOfRow) {
        case 0:
        {
            return 10;
        }
            break;
        case 1:
        {
            return _rootClassOfAskInMyPublish.data.question.count;
        }
            break;
        default:
        {
            return _rootClassOfMyPublish.data.answer.count;
        }
            break;
    }
}
#pragma mark - 返回每个 row 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return SCREEN_HEIGHT / 2.5;
}
#pragma mark - 分区头的文字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"地方阿萨德";
}
#pragma mark - TableView 代理方法 cell 的赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (_numberOfRow) {
        case 0:
        {
            TVCellOfArticleInMyPublish *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfArticleInMyPublish" forIndexPath:indexPath];
            return cell;
        }
            break;
        case 1:
        {
            TVCellOfAskInMyPublish *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfAskInMyPublish" forIndexPath:indexPath];
            cell.createdLabel.text = _rootClassOfAskInMyPublish.data.question[indexPath.row].created;
            cell.titleLabel.text = _rootClassOfAskInMyPublish.data.question[indexPath.row].title;
            cell.contentLabel.text = _rootClassOfAskInMyPublish.data.question[indexPath.row].content;
            cell.commentnumLabel.text = _rootClassOfAskInMyPublish.data.question[indexPath.row].commentnum;
            return cell;
        }
            break;
        default:
        {
            TVCellOfMyPublish *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfMyPublish" forIndexPath:indexPath];
            cell.questionContentLabel.text = _rootClassOfMyPublish.data.answer[indexPath.row].question.content;
            cell.answerContentLabel.text = [NSString stringWithFormat:@"我的回复:%@", _rootClassOfMyPublish.data.answer[indexPath.row].content];
            [cell.answerContentLabel alignTop];
            cell.replynumLabel.text = _rootClassOfMyPublish.data.answer[indexPath.row].replynum;
            cell.votenumLabel.text = _rootClassOfMyPublish.data.answer[indexPath.row].votenum;
            return cell;
        }
            break;
    }
}
#pragma mark - tableView 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (_numberOfRow) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            
        }
            break;
        default:
        {
            
        }
            break;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
